export async function apiFetch<T>(url: string, options: RequestInit = {}) {
  const defaultHeaders = {
    'Content-Type': 'application/json',
    'satoken': localStorage.getItem('token') || ''
  };
  const res = await fetch(url, {
    credentials: 'same-origin',
    headers: {
      ...defaultHeaders,
      ...(options.headers || {})
    },
    ...options
  });
  if (!res.ok) {
    throw new Error(`HTTP error! status: ${res.status}`);
  }
  const data = await res.json();
  return data as T;
}